********************************************************************************
************************* Do File (8): Table A1.2 ******************************
********************************************************************************

clear
matrix drop _all
set more off

use "$data/EPH_1015_format.dta", clear

destring occupation occupation_unemp occup_all, replace

*** Keep only observations that have all controls used

keep if (occupation !=. & underemp != . & cont_pens !=. & domwk_all !=. & linc_mjob_base08 !=. & lwagehr_mjob_base08 !=. & linc_total_base08 != . & lhours_mjob !=. & age !=. & hhsize !=. & tenure !=. & msa !=. & educyr !=. ///
& attsch_ever !=. & native !=. & lit !=. & gender !=.) | (occupation_unemp != . & age !=. & hhsize !=. & msa !=. & educyr !=. & attsch_ever !=. & native !=. & lit !=. & gender !=.)

********************************************************************************
********************************************************************************

*** Locals for controls

local occup occupation
local base_controls "msa year"
local controls "age age2 hhsize lit native attsch_ever educyr educyr2 i.marstat i.dec_pcfaminc"


*** Label the variables as they appear in the table

label var hours_mjob "Hours of work"
label var lhours_mjob "Hours of work"


********************************************************************************
********************************************************************************

*** Create the full-time dummies

gen fulltime35 = hours_mjob >= 35 & !missing(hours_mjob)
label var fulltime35 "Full-time worker"

gen fulltime30 = hours_mjob >= 30 & !missing(hours_mjob)
label var fulltime30 "Full-time worker"

********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

* Run regression for pension contribution to restrict the sample to use

qui reghdfe cont_pens domwk_all treat_dwall `controls' if ${ctrl_group} == 1 & unemployed == 0, absorb(`base_controls' `occup') vce(cluster msa)
gen sample_reg = 1 if e(sample)

* Full time worker defined as those who work 30 hours or more

local varlabel: variable label fulltime30
qui reghdfe fulltime30 domwk_all treat_dwall `controls' if sample_reg == 1, absorb(`base_controls' `occup') vce(cluster msa)
sum fulltime30 if domwk_all == 1 & treat == 0 & e(sample)
local meanvar = r(mean)
outreg2 using "$tables/Table A1_2", replace excel keep(treat_dwall) nocons dec(3) label ctitle(`varlabel') addstat(Mean dependent variable,`meanvar') addtext(Controls, Yes, Year Fixed Effects, Yes, Occupation Fixed Effects, Yes, Metropolitan Area Fixed Effects, Yes, Number of clusters, "`e(N_clust)'")

local varlabel: variable label hours_mjob
qui reghdfe lhours_mjob domwk_all treat_dwall `controls' if sample_reg == 1 & fulltime30 == 0, absorb(`base_controls' `occup') vce(cluster msa)
sum hours_mjob if domwk_all == 1 & treat == 0 & e(sample)
local meanvar = r(mean)
outreg2 using "$tables/Table A1_2", append excel keep(treat_dwall) nocons dec(3) label ctitle(`varlabel') addstat(Mean dependent variable,`meanvar') addtext(Type of worker, Part-time, Controls, Yes,Year Fixed Effects, Yes, Occupation Fixed Effects, Yes, Metropolitan Area Fixed Effects, Yes, Number of clusters, "`e(N_clust)'")

local varlabel: variable label hours_mjob
qui reghdfe lhours_mjob domwk_all treat_dwall `controls' if sample_reg == 1 & fulltime30 == 1, absorb(`base_controls' `occup') vce(cluster msa)
sum hours_mjob if domwk_all == 1 & treat == 0 & e(sample)
local meanvar = r(mean)
outreg2 using "$tables/Table A1_2", append excel keep(treat_dwall) nocons dec(3) label ctitle(`varlabel') addstat(Mean dependent variable,`meanvar') addtext(Type of worker, Part-time, Controls, Yes,Year Fixed Effects, Yes, Occupation Fixed Effects, Yes, Metropolitan Area Fixed Effects, Yes, Number of clusters, "`e(N_clust)'")


* Full time worker defined as those who work 35 hours or more

local varlabel: variable label fulltime35
qui reghdfe fulltime30 domwk_all treat_dwall `controls' if sample_reg == 1, absorb(`base_controls' `occup') vce(cluster msa)
sum fulltime30 if domwk_all == 1 & treat == 0 & e(sample)
local meanvar = r(mean)
outreg2 using "$tables/Table A1_2", append excel keep(treat_dwall) nocons dec(3) label ctitle(`varlabel') addstat(Mean dependent variable,`meanvar') addtext(Controls, Yes, Year Fixed Effects, Yes, Occupation Fixed Effects, Yes, Metropolitan Area Fixed Effects, Yes, Number of clusters, "`e(N_clust)'")

local varlabel: variable label hours_mjob
qui reghdfe lhours_mjob domwk_all treat_dwall `controls' if sample_reg == 1 & fulltime35 == 0, absorb(`base_controls' `occup') vce(cluster msa)
sum hours_mjob if domwk_all == 1 & treat == 0 & e(sample)
local meanvar = r(mean)
outreg2 using "$tables/Table A1_2", append excel keep(treat_dwall) nocons dec(3) label ctitle(`varlabel') addstat(Mean dependent variable,`meanvar') addtext(Type of worker, Part-time, Controls, Yes,Year Fixed Effects, Yes, Occupation Fixed Effects, Yes, Metropolitan Area Fixed Effects, Yes, Number of clusters, "`e(N_clust)'")

local varlabel: variable label hours_mjob
qui reghdfe lhours_mjob domwk_all treat_dwall `controls' if sample_reg == 1 & fulltime35 == 1, absorb(`base_controls' `occup') vce(cluster msa)
sum hours_mjob if domwk_all == 1 & treat == 0 & e(sample)
local meanvar = r(mean)
outreg2 using "$tables/Table A1_2", append excel keep(treat_dwall) nocons dec(3) label ctitle(`varlabel') addstat(Mean dependent variable,`meanvar') addtext(Type of worker, Part-time, Controls, Yes,Year Fixed Effects, Yes, Occupation Fixed Effects, Yes, Metropolitan Area Fixed Effects, Yes, Number of clusters, "`e(N_clust)'")
